package com.xc.sbdemo;

import com.xc.sbdemo.comm.XcInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
@Api
@RestController
public class HelloController {
    @Resource
    private XcInfo xcInfo;

    @Value("${com.xc.name}")
    private String name;
    @Value("${com.xc.email}")
    private String email;
    @ApiOperation("Hello Spring Boot方法")
    @ResponseBody
    @GetMapping("/hello")
    public String hello(){
        int num=1/0;
        return "hello sb"+xcInfo.getName()+xcInfo.getEmail();
    }

    @ExceptionHandler(RuntimeException.class)
    public String handler(Exception e, Model model){
        model.addAttribute("level");
        return "error";
    }
}
